<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>주문관리</title>
<link href="/Jangdolbaeng2/css/bootstrap.min.css" rel="stylesheet">
<link href="/Jangdolbaeng2/css/customer/common.css" rel="stylesheet">
<script src="/Jangdolbaeng2/js/jquery-1.11.1.js"></script>
<script src="/Jangdolbaeng2/js/bootstrap.min.js"></script>
<style type="text/css">

tr {
	height: 45px;
}



</style>

<script type="text/javascript">
$(document).ready(function() {
	$('.dropdown-toggle').dropdown();
});



function delivery_go(order_seq) {
		
	if(confirm("배송중으로 표시할까요?")){
		location.href="delivery_go.action?order_seq=" + order_seq;		
	}
	
}//delivery_go()

function delivery_cancel(order_seq) {
		
	if(confirm("배송준비로 표시할까요?")){
		location.href="delivery_cancel.action?order_seq=" + order_seq;		
	}
	
}//delivery_cancel()

function orderDay(day) {
	
	$.ajax({
		url: 'orderForm.action',
		type: 'POST',
		dateType: 'html',
		data: 
		{
			orderDay: day
		},
		success: function (html) {
			$('#orderPage').html(html);
		}
	});
	
}//orderDays()

function orderSort(type) {
	
	$.ajax({
		url: 'orderSort.action',
		type: 'POST',
		dateType: 'html',
		data: 
		{
			type: type
		},
		success: function (html) {
			$('#orderPage').html(html);
		}
	});		

}//orderList()

function searchBtn(type) {	
	
	if(type == 'none') {
		$('#btnSearch').css('display', type);
		$('#txtSearch').val('');		
	}
	else {
		$('#btnSearch').css('display', type);
	}	
	
}//searchBtn()

function searchById() {
	
	var id = $('#txtSearch').val();	
	
	$.ajax({
		url: 'orderSortbyId.action',
		type: 'POST',
		dateType: 'html',
		data: 
		{
			id: id
		},
		success: function (html) {
			$('#orderPage').html(html);
		}
	});
}//searchById()


</script>



</head>
<body id="orderPage">
<center>
<div id="header">
<%@ include file="adminHeader.jsp" %>
</div>

<div class="container">
	<div class="row" align="center"> 
		<h3 align="center" style="margin-top: 50px; margin-bottom: 20px;"><span class="glyphicon glyphicon-list-alt"></span> <span style="font-family: anew">주문내역</span></h3>
	</div>
	
	<div class="row" align="center">
		<table class="table table-striped table-hover table-bordered" style="text-align: center;">
			<tr class="success" style="height: 30px; font-weight: bold; font-family: anew;">
				<td style="padding-top: 15px;">주문번호</td>
				<td><div class="form-group" style="display: inline-table; margin-bottom: 0px;">
			          <input type="text" class="form-control" placeholder="구매자아이디" style="width: 120px; text-align: center" onclick="javascript: searchBtn('block')" id="txtSearch">
			        </div>
			        <div style="display: none;" id="btnSearch">
				        <button type="submit" class="btn btn-default" onclick="javascript: searchById()" >검색</button>
				        <button type="submit" class="btn btn-default" onclick="javascript: searchBtn('none')">취소</button>
			        </div>
				</td>
				<td><div class="btn-group">
					  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
					   <span style="font-family: anew; font-weight: bold;">배달유형</span> <span class="caret"></span>
					  </button>
					  <ul class="dropdown-menu" role="menu">
					    <li><a href="javascript: orderSort('s');">배달</a></li>
					    <li><a href="javascript: orderSort('d');">직접수령</a></li>					    
					  </ul>
					</div>
  				</td>
				<td><div class="btn-group">
					  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
					   <span style="font-family: anew; font-weight: bold;">배송상태</span> <span class="caret"></span>
					  </button>
					  <ul class="dropdown-menu" role="menu">
					    <li><a href="javascript: orderSort('o');">배송중</a></li>
					    <li><a href="javascript: orderSort('f');">배송준비</a></li>
					    <li><a href="javascript: orderSort('t');">배송완료/수령완료</a></li>				    
					  </ul>
					</div>
				</td>		
				<td><div class="btn-group">
					  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
					   <span style="font-family: anew; font-weight: bold;">주문날짜</span> <span class="caret"></span>
					  </button>
					  <ul class="dropdown-menu" role="menu">
					    <li><a href="javascript: orderDay('3');">3일</a></li>
					    <li><a href="javascript: orderDay('7');">7일</a></li>
					    <li><a href="javascript: orderDay('15');">15일</a></li>				    
					  </ul>
					</div>			    			
				</td>
				<td style="padding-top: 15px;">배송상태변경</td>		
			</tr>	
		<s:iterator value="orderList" id="olist">
			<tr>
				<s:url id="order_seq_action" action="order_detail">
					<s:param name="order_seq" value="%{order_seq}" />
				</s:url>
				<td><s:a href="%{order_seq_action}" style="color: blue;"><s:property value="order_seq"/></s:a></td>
				<td><s:property value="customer_id"/></td>
				<td><s:if test="order_type == 'd'">직접수령</s:if>
					<s:else>배달</s:else>
				</td>
				<td><s:if test="order_type == 'd' && result == 'f'">미수령</s:if>
					<s:elseif test="order_type == 'd' && result == 't'">수령완료</s:elseif>
					<s:elseif test="result == 'f'">배송준비</s:elseif>
					<s:elseif test="result == 'o'">배송중</s:elseif>
					
					<s:else>배송완료</s:else>
				</td>		
				<td><s:property value="inputdate"/></td>
				<td><s:if test="order_type != 'd'">				
					<div class="btn-group">
					  <button type="button" class="btn btn-success" onclick="javascript:delivery_go('${order_seq}')">배송중</button>					  
					  <button type="button" class="btn btn-info" onclick="javascript:delivery_cancel('${order_seq}')">배송준비</button>
					</div>
					</s:if>
					<s:else>직접수령</s:else>
				</td>
					
			</tr>	
		</s:iterator>
		</table>
	</div>
</div><!-- end of container -->
</center>

</body>
</html>